package com.benjaminwan.read.free.config

import com.benjaminwan.read.free.model.ItemConfig
import com.benjaminwan.read.free.model.enums.ItemType
import com.benjaminwan.read.free.model.action.MouseButtonDown
import com.benjaminwan.read.free.model.action.Position
import com.benjaminwan.read.free.model.enums.MouseButton
import com.benjaminwan.read.free.model.listOfItemConfig
import com.benjaminwan.read.free.ui.main.MainViewModel
import com.benjaminwan.read.free.utils.showPicker
import com.xuexiang.xui.widget.textview.supertextview.SuperTextView

object MouseButtonDownConfig {
    fun getMouseButtonDownConfig(mainVM: MainViewModel, pos: Position): List<ItemConfig> {
        return listOfItemConfig {
            itemConfig {
                type = ItemType.Text
                titleStr = "按键"
                optionFunc = { Options.optionMouseButton }
                rightTextFunc =
                    { Options.getAction<MouseButtonDown>(mainVM, pos)?.which?.name ?: "" }
                click = { view ->
                    (view as SuperTextView).showPicker(title, options) { opValue, opName ->
                        if (opName == view.rightString) return@showPicker
                        val action =
                            Options.getAction<MouseButtonDown>(mainVM, pos) ?: return@showPicker
                        val which = MouseButton.valueOf(opName)
                        mainVM.setAction(pos, action.copy(which = which))
                    }
                }
            }
        }
    }
}